<template>

</template>

<script>
import axios from 'axios'
import utils from '@/utils'
import {
  removeToken,
  setAllianceId,
  setrefsToken,
  setToken
} from "@/utils/auth";
import store from "@/store";
export default {
  name: "account",
  data() {
    return {}
  },
  created() {
    this.getUrldata()
  },
  mounted() {
  },
  methods: {
    getUrldata () {
      removeToken()
      localStorage.removeItem('supportsystem_shopName')
      localStorage.removeItem('supportsystem_code')
      let token = this.$route.query.token
      let code = this.$route.query.code
      let businessId = this.$route.query.businessId
      let fzurlPath = `?token=${token}&code=${code}&businessId=${businessId}`
      localStorage.setItem('supportsystem_fzurlPath',fzurlPath)

      const axiosAjax = axios.create({
        timeout: 1000 * 60,
        baseURL: utils.XZBaseApi()
      })
      axiosAjax.get('/xzapi/ledger/account/queryLedgerToken', { params:{token,code,businessId} }).then( async res => {
        if ( res.data.retcode !== 0 ) {
          setToken('token')
          this.$router.push('/')
          this.$message.error(res.data.retmsg)
          return
        }
        let allianceId = res.data.retdata?.allianceId || ''
        let shopName = res.data.retdata?.shopName || '--'
        let refresh_token = res.data?.retdata?.refresh_token || ''
        let token = 'Bearer '+ res.data?.retdata?.access_token
        setToken(token)
        setrefsToken(refresh_token)
        setAllianceId(allianceId)
        localStorage.setItem('supportsystem_code',code)
        localStorage.setItem('supportsystem_shopName',shopName)
        await this.$store.dispatch('getMenus')
        this.$router.push({ path:store.state.powerList[1]})

        //服务端要求进系统调下
        this.$http.LogoService.pmsConfig({})
      }).catch( async rd => {
        setToken('token')
        this.$router.push('/')
      })
    },
  }
}
</script>

<style scoped>

</style>
